<?php
namespace App\Services\Resume;

//基础service  一些公共的方法的基类
use App\Model\Usera;
use App\Services\CommonService;
use Illuminate\Http\Request;
use App\Model\Resume;
use Illuminate\Support\Facades\DB;

/*
 *  service 调用 model
 */
class ResumeService extends CommonService
{
    protected $model;
    public function __construct()
    {
        $this->model=new Resume();
    }

    /*
     *  简历列表
     *  @ $id  用户id
     */
    static function lists($id){
        $res = Resume::lists($id);
        // 将对象转化为数组
        foreach( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }

    /*
     *  新建简历  将用户id  添加入库  状态不可用
     *  @ $id  用户id
     */
    static function add($id)
    {
        // 添加数据并获取新 id
        $id = Resume::add($id);
        $name = "简历".$id;
        //通过模型更新数据
        $time = time();
        //$num = Resume::where('industry_id','=',$id)->update(['age'=>"$name"]);
        DB::update("update resume set `r_name`='$name',`time`=$time where `industry_id`=$id");
        return $id;

    }

    /*
     *  新建简历  需要查询出用户基本信息
     *  @ $id  用户id
     *  @ $resume_id  新的简历id
     */
    static function users($id,$resume_id){
        $res = Resume::look_user($id);
        // 将对象转化为数组
        foreach ( $res as &$v ){
            $v = (array)$v;
            $v['resume_id'] = $resume_id;
        }
        return $res;
    }

    /*
     *  新建简历  进行一些基本信息的添加（获取最新id进行修改）
     *  并将状态改为 可用
     *  $arr  更细的数据
     */
    static function updainfor($arr){
        $arr['status'] = 0;
        $data =DB::table('resume')
         ->where('industry_id', $arr['industry_id'])
        ->update($arr);
        return $data;
    }

    /*
     * 新建简历  获取最新id进行修改
     */
    static function upda($arr){
        $data =DB::table('resume')
            ->where('industry_id', $arr['industry_id'])
            ->update($arr);
        return $data;
    }


    /*
     *  查询简历详情
     *   @id  简历id
     */
    static function detail($id){
        $res = Resume::detail($id);
        foreach ( $res as &$v ){
            $v = (array)$v;
            if($v['political_outlook'] == 1){
                $v['political_outlook'] = '党员';
            }else{
                $v['political_outlook'] = '无';
            }

        }
        return $res;
    }
    /**
     * 简历列表
     */
    public function resumeList($id){
       $res=$this->model->resumeList($id);
       return $res;
    }
    /**
     * 按照职位搜索
     */
    public function searchOffname($offname,$school,$study,$major){
        //职位
        if(!empty($offname)&&empty($school)&&empty($study)&&empty($major)){
            $res=$this->model->searchOff($offname);
        }
        //学校
        if (!empty($school)&&empty($offname)&&empty($study)&&empty($major)){
            $res=$this->model->searchSchool($school);
        }
        //学历
        if (!empty($study)&&empty($offname)&&empty($major)&&empty($school)){
            $res=$this->model->searchStudy($study);
        }
        //专业
        if (!empty($major)&&empty($study)&&empty($offname)&&empty($school)){
            $res=$this->model->searchMajor($major);
        }
        if (!empty($offname)&&!empty($study)&&empty($school)&&empty($major)){
            $res=$this->model->seachOffSch($offname,$study);
        }
        return $res;
    }

    /*
     *  查出所有的行业
     */
    static function selindustry(){
        $res = DB::select("select * from industry");
        foreach( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }

}